package com.sky.controller.user;

import com.sky.constant.StatusConstant;
import com.sky.entity.Dish;
import com.sky.result.Result;
import com.sky.service.DishService;
import com.sky.vo.DishVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController(value = "userDishController")
@Slf4j
@RequestMapping("/user/dish")
public class DishController {
    @Autowired
    private RedisTemplate redisTemplate;
    @Autowired
    private DishService dishService;

    /**
     * 根据分类id查询菜品
     */
    @Cacheable(cacheNames = "dishCache",key = "#categoryId")
    @GetMapping("/list")
    public Result<List<DishVO>> dishList(Long categoryId){
        //根据categoryId在redis中查询是否存在
        Dish dish = new Dish();
        dish.setStatus(StatusConstant.ENABLE);
        dish.setCategoryId(categoryId);
        List<DishVO> list = dishService.selectWithFlavorsByCategoryId(dish);
        return Result.success(list);
    }

}
